<!DOCTYPE HTML>
<html>
<head>
    <!-- support for mobile touch devices -->
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">

    <!-- twitter bootstrap CSS stylesheet - not required by cornerstoneTools -->
    <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">

    <link href="../cornerstone.min.css" rel="stylesheet">

</head>
<body>
<div class="container">
    <div class="page-header">
        <h1>
            Reference Lines Example
        </h1>
        <p>
            This page contains an example of the reference lines tool.
        </p>

    </div>

    <div class="row">
        <div class="col-xs-2">
            <ul class="list-group">
                <a id="enable" class="list-group-item active">Enable</a>
                <a id="disable" class="list-group-item">Disable</a>
            </ul>
        </div>
        <div class="col-xs-10">
            <div style="width:256px;height:256px;position:relative;display:inline-block;color:white;"
                 oncontextmenu="return false"
                 class='cornerstone-enabled-image'
                 unselectable='on'
                 onselectstart='return false;'
                 onmousedown='return false;'>
                <div id="axial"
                     style="width:256px;height:256px;top:0px;left:0px; position:absolute;">
                </div>
            </div>
            <div style="width:256px;height:256px;position:relative;display:inline-block;color:white;"
                 oncontextmenu="return false"
                 class='cornerstone-enabled-image'
                 unselectable='on'
                 onselectstart='return false;'
                 onmousedown='return false;'>
                <div id="coronal"
                     style="width:256px;height:256px;top:0px;left:0px; position:absolute;">
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<!-- include the cornerstone library -->
<script src="../cornerstone.min.js"></script>
<script src="../cornerstoneMath.min.js"></script>

<!-- include the cornerstone tools library -->
<script src="../../dist/cornerstoneTools.js"></script>
<script>window.cornerstoneTools || document.write('<script src="https://unpkg.com/cornerstone-tools">\x3C/script>')</script>

<!-- include special code for these examples which provides images -->
<script src="../exampleImageLoader.js"></script>
<script src="../exampleMetaDataProvider.js"></script>

<script>
    var axialElement = document.getElementById('axial');
    var coronalElement = document.getElementById('coronal');

    var axialImageIds = [
        'example://1',
        'example://2'
    ];

    var axialStack = {
        currentImageIdIndex : 0,
        imageIds: axialImageIds
    };

    var synchronizer = new cornerstoneTools.Synchronizer("cornerstonenewimage", cornerstoneTools.updateImageSynchronizer);

    // image enable the dicomImage element
    cornerstone.enable(axialElement);
    cornerstone.enable(coronalElement);

    // Enable mouse inputs
    cornerstoneTools.mouseInput.enable(axialElement);
    cornerstoneTools.mouseWheelInput.enable(axialElement);

    var axialPromise = cornerstone.loadImage(axialImageIds[0]).then(function(image) {
        // display this image
        cornerstone.displayImage(axialElement, image);

        // set the stack as tool state
        cornerstoneTools.addStackStateManager(axialElement, ['stack', 'referenceLines']);
        cornerstoneTools.addToolState(axialElement, 'stack', axialStack);

        // Enable all tools we want to use with this element
        cornerstoneTools.pan.activate(axialElement, 1);
        cornerstoneTools.zoom.activate(axialElement, 4);
        cornerstoneTools.stackScrollWheel.activate(axialElement);

        // Add the enabled elements to the synchronization context
        synchronizer.add(axialElement);

        // enable reference Lines tool
        cornerstoneTools.referenceLines.tool.enable(axialElement, synchronizer);
    });

    var coronalPromise = cornerstone.loadImage('example://3').then(function(image) {
        // display this image
        cornerstone.displayImage(coronalElement, image);

        // Add the enabled elements to the synchronization context
        synchronizer.add(coronalElement);

        // enable reference Lines tool
        cornerstoneTools.referenceLines.tool.enable(coronalElement, synchronizer);
    });

    Promise.all([axialPromise, coronalPromise]).then(function() {
        function activate(id) {
            document.querySelectorAll('a').forEach(function(elem) {
              elem.classList.remove('active');
            });
            document.getElementById(id).classList.add('active');
        }

        document.getElementById('enable').addEventListener('click', function() {
            activate("enable");
            cornerstoneTools.referenceLines.tool.enable(coronalElement);
            cornerstoneTools.referenceLines.tool.enable(axialElement);
            return false;
        });
        document.getElementById('disable').addEventListener('click', function() {
            activate("disable");
            cornerstoneTools.referenceLines.tool.disable(coronalElement);
            cornerstoneTools.referenceLines.tool.disable(axialElement);
            return false;
        });
    });



</script>
</html>
